if( typeof Object.create !== 'function' ){
	Object.create = function ( obj ) {
		function F(){};
		F.prototype = obj;
		return new F();
	};
}

(function( $, window, document, undefined ){
	
	var ToolTip = {
		offsetX : "30",
		offsetY : "30",
		
		init: function(options, elem){
			var self = this;
			self.elem = elem;
			self.$elem = $(elem);
			
			self.$elem.on("mouseenter", function(e){
				$('.toolTip').fadeOut("slow").remove().delay(500);
				self.linkType(self.$elem.attr('href'));
				$('.toolTip').css("left", e.pageX + 20 + "px")
								.css("top", e.pageY - 20 + "px");
				$('.toolTip').animate({ opacity: 1, top: "+=20"}, 200, function(){
					$(this).append(self.embedElem);
					
				});
			});
			
			self.$elem.on("mouseleave", function(){
				$('.toolTip').fadeOut("slow").remove().delay(500);
			});
		},
		
		linkType : function(link ){
			if(link.search("www.youtube.com") != -1){
				this. embedElem = this.youtube(link);
			}
		    else if(link.match("(https?:\/\/.*\.(?:png|jpg|jpeg|gif|bmp))") != null ) {
				$("body").append("<p class='toolTip'><img src='"+ link +"' alt='url preview' /></p>");
				$(".toolTip img").css("max-height", "250px");
			}
		},
		
		youtube: function(link){
			var startPosition = link.indexOf("v=") + 2;
			var endPosition = (link.indexOf("&") != -1)?link.indexOf("&"): link.length;
			var videoId = link.substring(startPosition, endPosition);
			
			var element = $("<div class='toolTip'></div>");
			var youtubeObj = '<object width="320" height="215">';
			youtubeObj += ' <param name="movie" value="http://www.youtube.com/v/' + videoId +'?version=3&amp;hl=en_US&autoplay=1"></param>';
			youtubeObj += '<embed src="http://www.youtube.com/v/'+ videoId +'?version=3&amp;hl=en_US&autoplay=1" type="application/x-shockwave-flash" width="320" height="215" ></embed>';
			youtubeObj += '</object>';
			
			/*var iframe = $("<iframe width='320' height='215' src='http://www.youtube.com/embed/"+ videoId +"?rel=0&autoplay=1&controls=0' frameborder='0' ></iframe>");*/
			$("body").append(element);
			$(".toolTip").css({width: "320", height: "215"});
			return youtubeObj;
		}
		
		
	};

	$.fn.toolTip = function( options ){		
		return this.each(function(){
			var tt = Object.create(ToolTip);
			tt.init(options, this);
		});
	};
	
	$.fn.toolTip.options = {
	
	};
	
}) (jQuery, window, document);